﻿using System;
using Microsoft.Data.Schema.Tools.DataGenerator;
using Microsoft.Data.Schema.Extensibility;
using Microsoft.Data.Schema.Sql;

namespace Lambda3.VisualStudio.DataTools.Generators.Cpf
{
    [DatabaseSchemaProviderCompatibility(typeof(SqlDatabaseSchemaProvider))]
    [Generator(typeof(CpfDataGeneratorDesigner))]
    public class CpfDataGenerator: Generator
    {
        private Random _Random;

        [Input(DefaultValue=true, Name="Include Group Separator", Description="Includes periods in the output as group separators, creating three groups of three digits each")]
        public bool IncludeGroupSeparator { get; set; }

        [Input(DefaultValue = true, Name = "Include Digit Separator", Description = "Includes a dash in the output as a check digit separator")]
        public bool IncludeDigitSeparator { get; set; }

        [Output(Name="CPF")]
        public string Output { get; set; }

        protected override void OnInitialize(GeneratorInit initInfo)
        {
            _Random = new Random(Seed);

            base.OnInitialize(initInfo);
        }

        protected override void OnGenerateNextValues()
        {
            GenerateNextCpf();
        }

        private void GenerateNextCpf()
        {
            var randomCpf = new Cpf(_Random.Next(999999999), IncludeGroupSeparator, IncludeDigitSeparator);

            Output = randomCpf.ToString();
        }
    }
}
